home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume9 / scanlog.pl < prev    next >
Encoding:
Text File  |  1989-12-12  |  8.0 KB  |  314 lines

  1. Newsgroups: comp.sources.misc
  2. organization: Multihouse NV, the Netherlands
  3. subject: v09i059: analysis of Bnews logfile
  4. from: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5. Reply-To: jv@mh.nl (Johan Vromans)
  6.  
  7. Posting-number: Volume 9, Issue 59
  8. Submitted-by: jv@mh.nl (Johan Vromans)
  9. Archive-name: scanlog.pl
  10.  
  11. The following perl program reads a Bnews logfile, and produces reports.
  12.  
  13. #---------------------------------- cut here ----------------------------------
  14. #!/bin/sh
  15. # This is a shell archive.  Remove anything before this line,
  16. # then unpack it by saving it in a file and typing "sh file".
  17. #
  18. # Wrapped by Johan Vromans <jv@mhres> on Sun Dec 10 14:53:47 1989
  19. #
  20. # This archive contains:
  21. #    scanlog.pl    
  22. #
  23. # Error checking via wc(1) will be performed.
  24.  
  25. LANG=""; export LANG
  26.  
  27. echo x - scanlog.pl
  28. sed 's/^@//' >scanlog.pl <<'@EOF'
  29. #!/usr/bin/perl -s
  30.  
  31. # This program requires perl version 3.0, patchlevel 4 or higher
  32.  
  33. # @(#)@ scanlog    1.2 - scanlog.pl
  34.  
  35. # This program scans a BNews logfile (default "/usr/lob/news/log"),
  36. # and produces statistics.
  37. #
  38. # It is able to generate three different reports.  The reports are
  39. # written to standard output. Unrecognized log entries are written to
  40. # standard error, together with their line numbers in the logfile. These
  41. # entries usually need manual inspection, or may be used to enhance the
  42. # program logic.
  43. # These are the reports:
  44. #  1. Report of articles received, posted, ... for each host
  45. #     For each news host, the following messages are tallied and
  46. #     reported:
  47. #       Recv'd: # of articles received
  48. #       Posted: # of articles posted
  49. #       Xmit'd: # of articles sent to other hosts
  50. #       Ctrl:   # of control messages
  51. #       Cancel: # of cancel messages
  52. #       Junked: # of articles moved to junk
  53. #       Dupl:   # of duplicate, hence rejected, articles
  54. #     Report format:
  55. #       News logfile report from Dec  3 05:21 to Dec 10 04:27
  56. #       Host     Recv'd  Posted  Xmit'd    Ctrl  Cancel  Junked    Dupl
  57. #       ------- ------- ------- ------- ------- ------- ------- -------
  58. #       hp4nl     11653       0    1140      37      30      48       9
  59. #       local         0      18      11       0       0       0       0
  60. #       ------- ------- ------- ------- ------- ------- ------- -------
  61. #       Total     11653      18    1151      37      30      48       9
  62. #  2. Report of non-local newsgroups referenced
  63. #     For each newsgroup which was not localized, the references are
  64. #     tallied and reported:
  65. #       Unrecognized newsgroups from Dec  3 05:21 to Dec 10 04:27
  66. #       Newsgroup                   Refs
  67. #       --------------------------- ----
  68. #       tue.humour                     1
  69. #       philnet.general                1
  70. #  3. Report of new newsgroups created
  71. #     For each newsgroup is indicated if the group was created (i.e.
  72. #     via a newgroup message), and if the spool area was created (i.e.
  73. #     upon receipt of the first article).
  74. #       Newsgroups created from Dec  3 05:21 to Dec 10 04:27
  75. #       Newsgroup          created: group dir
  76. #       --------------------------- ----- ---
  77. #       alt.prose.d                         +
  78. #       alt.recovery                    +   +
  79. # Usage:
  80. #     scanlog [ options ] [ logfile ]
  81. #       options:
  82. #         -report     generate standard report
  83. #         -foreign    generate report of unknown groups
  84. #         -new        generate report of new groups
  85. #        default is all reports.
  86. #       logfile       name of the logfile to use
  87. #        default is "/usr/lib/news/log"
  88. # Copyright 1989 Johan Vromans
  89. # Declared public domain in the hope it may be useful to others as
  90. # well.
  91.  
  92. # run-time options
  93. #
  94. $do_report = defined $report;
  95. $do_foreign = defined $foreign;
  96. $do_new = defined $new;
  97.  
  98. # default values
  99. $do_report = $do_new = $do_foreign = 1 
  100.   unless ($do_report | $do_foreign | $do_new);
  101.  
  102. # default logfile
  103. @@ARGV = ("/usr/lib/news/log") if $#ARGV < 0;
  104.  
  105. $firstdate = $lastdate = "";
  106.  
  107. # process logfile
  108. while ( $line = <> ) {
  109.  
  110.   chop ($line);
  111.   @a = split (/\t/, $line);
  112.   if ( $#a >= 2 ) {        # need three fields
  113.     $lastdate = $a[0];
  114.     $firstdate = $lastdate unless $firstdate;
  115.     $host = $a[1];
  116.     $used{$host}++;
  117.  
  118.     $msg = join(" ",@a[2..$#a]);    # join, in case the message was split
  119.  
  120.     # Analysis of messages
  121.     if ( $msg =~ /^received / ) {
  122.       $received{$host}++;
  123.     }
  124.     elsif ( $msg =~ /^Duplicate / ) {
  125.       $duplicate{$host}++;
  126.     }
  127.     elsif ( $msg =~ /^Cancelling / ) {
  128.       $cancelled{$host}++;
  129.     }
  130.     elsif ( $msg =~ /^Ctl Msg / ) {
  131.       $ctrl{$host}++;
  132.       if ( $' =~ /^(\S+) .*: newgroup / ) {
  133.         $created{$1} = "+";
  134.         $brandnew{$1} = "";
  135.       }
  136.     }
  137.     elsif ( $msg =~ /^linecount expected / ) {
  138.       # ignore
  139.     }
  140.     elsif ( $msg =~ /^No valid newsgroups / ) {
  141.       $junked{$host}++;
  142.     }
  143.     elsif ( $msg =~ /^posted / ) {
  144.       $posted{$host}++;
  145.     }
  146.     elsif ( $msg =~ / newsgroup (\S+) not localized$/ ) {
  147.       $foreign{$1}++;
  148.     }
  149.     elsif ( $msg =~ / sent to / ) {
  150.       $xmit{$host}++;
  151.     }
  152.  
  153.     # Misc
  154.     elsif ( $msg =~ /^make newsgroup (\S+) in dir / ) {
  155.       $brandnew{$1} = "+";
  156.     }
  157.  
  158.     # These entries are ignored
  159.     elsif ( $msg =~ /^Expired article / ) {
  160.     }
  161.     elsif ( $msg =~ /^Can't cancel .* non-existent$/ ) {
  162.     }
  163.  
  164.     # Notify
  165.     else {
  166.       print STDERR "? $. $line\n";
  167.     }
  168.   }
  169.   else {
  170.     printf STDERR "? $. $line\n";
  171.   }
  172. }
  173.  
  174. format std_hdr =
  175. News logfile report from @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  176. "$firstdate to $lastdate"
  177.  
  178. Host     Recv'd  Posted  Xmit'd    Ctrl  Cancel  Junked    Dupl
  179. @.
  180. format std_out =
  181. @@<<<<<< @>>>>>> @>>>>>> @>>>>>> @>>>>>> @>>>>>> @>>>>>> @>>>>>>
  182. $host, $received, $posted, $xmit, $ctrl, $cancelled, $junked, $duplicate
  183. @.
  184.  
  185. if ( $do_report ) {
  186.  
  187.   $^ = "std_hdr";
  188.   $~ = "std_out";
  189.  
  190.   $host = $received = $posted = $ctrl = $cancelled = 
  191.     $duplicate = $xmit = $junked = "--------";
  192.   write;
  193.  
  194.   $Treceived = $Tposted = $Tduplicate = $Txmit = 
  195.     $Tcancelled = $Tctrl = $Tjunked = 0;
  196.   foreach $host ( sort (keys (%used))) {
  197.     $Treceived += ($received = $received{$host});
  198.     $Tposted += ($posted = $posted{$host});
  199.     $Tduplicate += ($duplicate = $duplicate{$host});
  200.     $Tcancelled += ($cancelled = $cancelled{$host});
  201.     $Tctrl += ($ctrl = $ctrl{$host});
  202.     $Txmit += ($xmit = $xmit{$host});
  203.     $Tjunked += ($junked = $junked{$host});
  204.     write;
  205.   }
  206.  
  207.   $host = $received = $posted = $ctrl = $cancelled = 
  208.     $duplicate = $xmit = $junked = "--------";
  209.   write;
  210.  
  211.   $host = "Total";
  212.   $received = $Treceived;
  213.   $posted = $Tposted;
  214.   $duplicate = $Tduplicate;
  215.   $xmit = $Txmit;
  216.   $junked = $Tjunked;
  217.   $ctrl = $Tctrl;
  218.   $cancelled = $Tcancelled;
  219.   write;
  220. }
  221.  
  222. format for_hdr =
  223. Unrecognized newsgroups from @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  224. "$firstdate to $lastdate"
  225.  
  226. Newsgroup                      Refs
  227. ---------------------------- ------
  228. @.
  229. format for_out =
  230. @@<<<<<<<<<<<<<<<<<<<<<<<<<<< @>>>>>
  231. $group, $refs
  232. @.
  233.  
  234. if ( $do_foreign) {
  235.  
  236.   $^ = "for_hdr";
  237.   $~ = "for_out";
  238.   $- = 0;
  239.  
  240.   @foreign = sort (keys (%foreign));
  241.   if ( $#foreign >= 0 ) {
  242.  
  243.     foreach $group ( @foreign ) {
  244.       $refs = $foreign{$group};
  245.       write;
  246.     }
  247.   }
  248. }
  249.  
  250. format new_hdr =
  251. Newsgroups created from @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  252. "$firstdate to $lastdate"
  253.  
  254. Newsgroup           Created: group dir
  255. ---------------------------- ----- ---
  256. @.
  257. format new_out =
  258. @@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<  @   @
  259. $group, $cr, $dir
  260. @.
  261.  
  262. if ( $do_new ) {
  263.  
  264.   $^ = "new_hdr";
  265.   $~ = "new_out";
  266.   $- = 0;
  267.  
  268.   @brandnew = sort (keys (%brandnew));
  269.   if ( $#brandnew >= 0 ) {
  270.  
  271.     foreach $group ( @brandnew ) {
  272.  
  273.       $dir = $brandnew{$group};
  274.       $cr = $created{$group};
  275.       write;
  276.     }
  277.   }
  278. }
  279. @EOF
  280. set `wc -lwc <scanlog.pl`
  281. if test $1$2$3 != 26910176847
  282. then
  283.     echo ERROR: wc results of scanlog.pl are $* should be 269 1017 6847
  284. fi
  285.  
  286. chmod 444 scanlog.pl
  287.  
  288. exit 0
  289. -- 
  290. Johan Vromans                       jv@mh.nl via internet backbones
  291. Multihouse Automatisering bv               uucp: ..!{uunet,hp4nl}!mh.nl!jv
  292. Doesburgweg 7, 2803 PL Gouda, The Netherlands  phone/fax: +31 1820 62944/62500
  293. ------------------------ "Arms are made for hugging" -------------------------
  294.  
  295.